/** * Adds this object on the object bench. If you pass null as instanceName the object will have a * predefined name. If the object is not a valid one nothing will happen. * * @param instanceName The name you want this object to have on the bench. * @throws ProjectNotOpenException if the project to which this object belongs has been closed by * the user. * @throws PackageNotFoundException if the package to which this object belongs has been deleted * by the user. */ public void addToBench(String instanceName) throws ProjectNotOpenException, PackageNotFoundException { if (objectWrapper == null) { return; } // Not rational to add a null object, is it ? if (objectWrapper.getObject().isNullObject()) { return; } // If you want you may set the instance name here. Otherwise accept default if (instanceName != null) { objectWrapper.setName(instanceName); } // This should really always exists, no need to check Package aPackage = wrapperId.getBluejPackage(); PkgMgrFrame aFrame = wrapperId.getPackageFrame(); ObjectBench aBench = aFrame.getObjectBench(); aBench.addObject(objectWrapper); // load the object into runtime scope aPackage .getDebugger() .addObject(aPackage.getId(), objectWrapper.getName(), objectWrapper.getObject()); }
/** * Opens a project. * * @param directory Where the project is stored. * @return the BProject that describes the newly opened project or null if it cannot be opened. */ public final BProject openProject(File directory) { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); // Yes somebody may just call it with null, for fun.. if (directory == null) return null; Project openProj = Project.openProject(directory.getAbsolutePath(), null); if (openProj == null) return null; // a hack, since bluej does not handle "opening" of projects correctly. // this code should really be into openProject or it should not be possible to open // a project is the initial package name is not there. Package pkg = openProj.getCachedPackage(openProj.getInitialPackageName()); if (pkg == null) return null; // I make a new identifier out of this Identifier aProject = new Identifier(openProj, pkg); // This will make the frame if not already there. should not be needed... try { aProject.getPackageFrame(); } catch (ExtensionException exc) { } // Note: the previous Identifier is not used here. return openProj.getBProject(); }
@Override public Type visitRecordAccess(MicroParser.RecordAccessContext ctx) { Type recordType = visit(ctx.expr()); if (recordType instanceof RecordType) { Scope recordScope = ((RecordType) recordType).getContainedScope(); Identifier id = recordScope.resolve(ctx.ID().getText()); if (id != null) { Type exprType = id.getType(); typeMap.put(ctx, exprType); return exprType; } else { MicroCompilerV1.error( ctx, ctx.ID().getText() + " is not a member of " + ((RecordType) recordType).getRecordTypeName()); return VOID; } } else if (recordType instanceof ArrayType && ctx.ID().getText().equals("length")) { typeMap.put(ctx, INT); return INT; } else { MicroCompilerV1.error(ctx, "Not a record type"); return VOID; } }
/** * @param scalar * @return true if the scalar is defines as $GLOBALS call */ private static boolean checkGLOBALS(Scalar scalar) { final String stringValue = scalar.getStringValue(); if (scalar.getScalarType() != Scalar.TYPE_STRING || stringValue.length() < 3) { return false; } final char charAtZero = stringValue.charAt(0); final char charAtEnd = stringValue.charAt(stringValue.length() - 1); if (!detectString(charAtZero) || !detectString(charAtEnd)) { return false; } if (scalar.getParent().getType() == ASTNode.ARRAY_ACCESS) { ArrayAccess arrayAccess = (ArrayAccess) scalar.getParent(); final Expression variableName = arrayAccess.getName(); if (variableName.getType() == ASTNode.VARIABLE) { Variable var = (Variable) variableName; if (var.isDollared() && var.getName() instanceof Identifier) { final Identifier id = (Identifier) var.getName(); return id.getName().equals("_GLOBALS") // $NON-NLS-1$ || id.getName().equals("GLOBALS"); // $NON-NLS-1$ } } } return false; }
public Coverage copy() { Coverage dst = new Coverage(); copyValues(dst); dst.issuer = issuer == null ? null : issuer.copy(); dst.bin = bin == null ? null : bin.copy(); dst.period = period == null ? null : period.copy(); dst.type = type == null ? null : type.copy(); dst.subscriberId = subscriberId == null ? null : subscriberId.copy(); if (identifier != null) { dst.identifier = new ArrayList<Identifier>(); for (Identifier i : identifier) dst.identifier.add(i.copy()); } ; dst.group = group == null ? null : group.copy(); dst.plan = plan == null ? null : plan.copy(); dst.subPlan = subPlan == null ? null : subPlan.copy(); dst.dependent = dependent == null ? null : dependent.copy(); dst.sequence = sequence == null ? null : sequence.copy(); dst.subscriber = subscriber == null ? null : subscriber.copy(); dst.network = network == null ? null : network.copy(); if (contract != null) { dst.contract = new ArrayList<Reference>(); for (Reference i : contract) dst.contract.add(i.copy()); } ; return dst; }
private MathElement build(Element element) throws InkMLComplianceException { String n = element.getNodeName(); if (n.equals("apply")) { Element ce = (Element) element.getFirstChild(); Operator op = getOperator(ce); while (ce.getNextSibling() != null) { ce = (Element) ce.getNextSibling(); op.appendParameter((Value) build(ce)); } return op; } else if (n.equals("cn")) { return new Value(Double.parseDouble(element.getTextContent())); } else if (n.equals("exponentiale")) { return new Value(Math.E); } else if (n.equals("pe")) { return new Value(Math.PI); } else if (n.equals("true")) { return new Value(true); } else if (n.equals("false")) { return new Value(false); } else if (n.equals("ci")) { Identifier id = new Identifier(element.getTextContent()); this.parameters.put(id.getId(), id); return id; } else { throw new InkMLComplianceException("Element '" + n + "' is not supported"); } }
public void bind(String name, InkChannel.Type type, Object value) { if (parameters.containsKey(name)) { Identifier id = parameters.get(name); id.setValue(value); id.setValue(type); } }
public CareTeam copy() { CareTeam dst = new CareTeam(); copyValues(dst); if (identifier != null) { dst.identifier = new ArrayList<Identifier>(); for (Identifier i : identifier) dst.identifier.add(i.copy()); } ; dst.status = status == null ? null : status.copy(); if (type != null) { dst.type = new ArrayList<CodeableConcept>(); for (CodeableConcept i : type) dst.type.add(i.copy()); } ; dst.name = name == null ? null : name.copy(); dst.subject = subject == null ? null : subject.copy(); dst.period = period == null ? null : period.copy(); if (participant != null) { dst.participant = new ArrayList<CareTeamParticipantComponent>(); for (CareTeamParticipantComponent i : participant) dst.participant.add(i.copy()); } ; dst.managingOrganization = managingOrganization == null ? null : managingOrganization.copy(); return dst; }
@Test public void shouldInvokeVariableAtWhenVisitIdentifierOnLoadSideOfExpression() { Identifier identifier = mock(Identifier.class); when(identifier.isOnLoadSideOfExpression()).thenReturn(true); analyser.visit(identifier, "var", 3); verify(writer).invokeVariableAt("var", 3); }
protected void outputConvertedStruct( Struct struct, Signatures signatures, DeclarationsHolder out, Identifier callerLibraryClass, String callerLibrary, boolean onlyFields) throws IOException { Struct structJavaClass = convertStruct(struct, signatures, callerLibraryClass, callerLibrary, onlyFields); if (structJavaClass == null) return; if (result.config.putTopStructsInSeparateFiles && struct.findParentOfType(Struct.class) == null) { String library = result.getLibrary(struct); Identifier javaPackage = result.getLibraryPackage(library); Identifier fullClassName = ident(javaPackage, structJavaClass.getTag().clone()); if (result.config.runtime == JNAeratorConfig.Runtime.BridJ) structJavaClass.addAnnotation(new Annotation(org.bridj.ann.Library.class, expr(library))); structJavaClass.removeModifiers(ModifierType.Static); structJavaClass = result.notifyBeforeWritingClass(fullClassName, structJavaClass, signatures, library); if (structJavaClass != null) { PrintWriter pout = result.classOutputter.getClassSourceWriter(fullClassName.toString()); result.printJavaClass(javaPackage, structJavaClass, pout); pout.close(); } } else out.addDeclaration(decl(structJavaClass)); }
/** * Required for making object Parcelable. If you override this class, you must override this * method if you add any additional fields. */ public void writeToParcel(Parcel out, int flags) { out.writeInt(mIdentifiers.size()); LogManager.d(TAG, "serializing identifiers of size %s", mIdentifiers.size()); for (Identifier identifier : mIdentifiers) { out.writeString(identifier == null ? null : identifier.toString()); } out.writeDouble(getDistance()); out.writeInt(mRssi); out.writeInt(mTxPower); out.writeString(mBluetoothAddress); out.writeInt(mBeaconTypeCode); out.writeInt(mServiceUuid); out.writeInt(mDataFields.size()); for (Long dataField : mDataFields) { out.writeLong(dataField); } if (LogManager.isVerboseLoggingEnabled()) { LogManager.d(TAG, "writing " + mExtraDataFields.size() + " extra data fields to parcel"); } out.writeInt(mExtraDataFields.size()); for (Long dataField : mExtraDataFields) { out.writeLong(dataField); } out.writeInt(mManufacturer); out.writeString(mBluetoothName); }
public Substance copy() { Substance dst = new Substance(); copyValues(dst); if (identifier != null) { dst.identifier = new ArrayList<Identifier>(); for (Identifier i : identifier) dst.identifier.add(i.copy()); } ; if (category != null) { dst.category = new ArrayList<CodeableConcept>(); for (CodeableConcept i : category) dst.category.add(i.copy()); } ; dst.code = code == null ? null : code.copy(); dst.description = description == null ? null : description.copy(); if (instance != null) { dst.instance = new ArrayList<SubstanceInstanceComponent>(); for (SubstanceInstanceComponent i : instance) dst.instance.add(i.copy()); } ; if (ingredient != null) { dst.ingredient = new ArrayList<SubstanceIngredientComponent>(); for (SubstanceIngredientComponent i : ingredient) dst.ingredient.add(i.copy()); } ; return dst; }
// idStr is a integer string 0..3 public Map<String, String> getParticipantIdentifiers(String idStr) { Identifier identifier = Identifier.values()[0]; // default if (idStr.equals("1")) identifier = Identifier.values()[1]; else if (idStr.equals("2")) identifier = Identifier.values()[2]; else if (idStr.equals("3")) identifier = Identifier.values()[3]; return getParticipantIdentifiers(identifier); }
public Group copy() { Group dst = new Group(); copyValues(dst); if (identifier != null) { dst.identifier = new ArrayList<Identifier>(); for (Identifier i : identifier) dst.identifier.add(i.copy()); } ; dst.type = type == null ? null : type.copy(); dst.actual = actual == null ? null : actual.copy(); dst.code = code == null ? null : code.copy(); dst.name = name == null ? null : name.copy(); dst.quantity = quantity == null ? null : quantity.copy(); if (characteristic != null) { dst.characteristic = new ArrayList<GroupCharacteristicComponent>(); for (GroupCharacteristicComponent i : characteristic) dst.characteristic.add(i.copy()); } ; if (member != null) { dst.member = new ArrayList<GroupMemberComponent>(); for (GroupMemberComponent i : member) dst.member.add(i.copy()); } ; return dst; }
protected CommandEvaluator<Criterion, Object> compileIdentifierToValueCMP( IdentifierToValueCMP node) { Identifier id = node.getIdentifier(); if (id instanceof Field) { String name = id.getName(); Value value = node.getValue(); if (INSTANCE_ID_FIELD.equals(name)) { value.setValue(Long.valueOf((String) value.getValue())); } else if (INSTANCE_STARTED_FIELD.equals(name) || INSTANCE_LAST_ACTIVE_FIELD.equals(name)) { try { value.setValue(ISO8601DateParser.parse((String) value.getValue())); } catch (ParseException ex) { throw new RuntimeException(ex); } } } if (node instanceof Equality) { return compileEqual((Equality) node); } else if (node instanceof Less) { return compileLess((Less) node); } else if (node instanceof Greater) { return compileGreater((Greater) node); } else if (node instanceof GE) { return compileGE((GE) node); } else if (node instanceof LE) { return compileLE((LE) node); } else if (node instanceof Like) { return compileLike((Like) node); } else { throw new IllegalArgumentException("Unsupported node " + node.getClass()); } }
static JsObjectImpl create( JsParserResult parserResult, ObjectNode objectNode, List<Identifier> fqName, ModelBuilder modelBuilder, boolean belongsToParent) { JsObjectImpl scope = modelBuilder.getCurrentObject(); JsObject parent = scope; JsObject result = null; Identifier name = fqName.get(fqName.size() - 1); JsObjectImpl newObject; if (!belongsToParent) { List<Identifier> objectName = fqName.size() > 1 ? fqName.subList(0, fqName.size() - 1) : fqName; parent = ModelUtils.getJsObject(modelBuilder, objectName); } result = parent.getProperty(name.getName()); newObject = new JsObjectImpl( parent, name, ModelUtils.documentOffsetRange( parserResult, objectNode.getStart(), objectNode.getFinish())); newObject.setDeclared(true); if (result != null) { // the object already exist due a definition of a property => needs to be copied for (String propertyName : result.getProperties().keySet()) { newObject.addProperty(propertyName, result.getProperty(propertyName)); } } JsDocumentationHolder docHolder = parserResult.getDocumentationHolder(); newObject.setDocumentation(docHolder.getDocumentation(objectNode)); parent.addProperty(name.getName(), newObject); return (JsObjectImpl) newObject; }
public DocumentReference copy() { DocumentReference dst = new DocumentReference(); dst.masterIdentifier = masterIdentifier == null ? null : masterIdentifier.copy(); dst.identifier = new ArrayList<Identifier>(); for (Identifier i : identifier) dst.identifier.add(i.copy()); dst.subject = subject == null ? null : subject.copy(); dst.type = type == null ? null : type.copy(); dst.subtype = subtype == null ? null : subtype.copy(); dst.author = new ArrayList<ResourceReference>(); for (ResourceReference i : author) dst.author.add(i.copy()); dst.custodian = custodian == null ? null : custodian.copy(); dst.authenticator = authenticator == null ? null : authenticator.copy(); dst.created = created == null ? null : created.copy(); dst.indexed = indexed == null ? null : indexed.copy(); dst.status = status == null ? null : status.copy(); dst.docStatus = docStatus == null ? null : docStatus.copy(); dst.supercedes = supercedes == null ? null : supercedes.copy(); dst.description = description == null ? null : description.copy(); dst.confidentiality = confidentiality == null ? null : confidentiality.copy(); dst.primaryLanguage = primaryLanguage == null ? null : primaryLanguage.copy(); dst.mimeType = mimeType == null ? null : mimeType.copy(); dst.format = format == null ? null : format.copy(); dst.size = size == null ? null : size.copy(); dst.hash = hash == null ? null : hash.copy(); dst.location = location == null ? null : location.copy(); dst.service = service == null ? null : service.copy(dst); dst.context = context == null ? null : context.copy(dst); return dst; }
public void assertParse(String identifier, String groupId, String artifactId, String version) { final Identifier id = new Identifier(identifier); assertEquals(id.getGroupId(), groupId, "Wrong group ID parsed from \"" + identifier + "\""); assertEquals( id.getArtifactId(), artifactId, "Wrong artifact ID parsed from \"" + identifier + "\""); assertEquals(id.getVersion(), version, "Wrong version parsed from \"" + identifier + "\""); }
public ProcessResponse copy() { ProcessResponse dst = new ProcessResponse(); copyValues(dst); if (identifier != null) { dst.identifier = new ArrayList<Identifier>(); for (Identifier i : identifier) dst.identifier.add(i.copy()); } ; dst.request = request == null ? null : request.copy(); dst.outcome = outcome == null ? null : outcome.copy(); dst.disposition = disposition == null ? null : disposition.copy(); dst.ruleset = ruleset == null ? null : ruleset.copy(); dst.originalRuleset = originalRuleset == null ? null : originalRuleset.copy(); dst.created = created == null ? null : created.copy(); dst.organization = organization == null ? null : organization.copy(); dst.requestProvider = requestProvider == null ? null : requestProvider.copy(); dst.requestOrganization = requestOrganization == null ? null : requestOrganization.copy(); dst.form = form == null ? null : form.copy(); if (notes != null) { dst.notes = new ArrayList<ProcessResponseNotesComponent>(); for (ProcessResponseNotesComponent i : notes) dst.notes.add(i.copy()); } ; if (error != null) { dst.error = new ArrayList<Coding>(); for (Coding i : error) dst.error.add(i.copy()); } ; return dst; }
@Override protected void setUp() throws Exception { super.setUp(); identifiable = new TestIdentifiable(); identifiable.addIdentifier(Identifier.createTemplate("MRN", MRN)); identifiable.getIdentifiers().get(0).setPrimaryIndicator(true); identifiable.addIdentifier(Identifier.createTemplate("SSN", SSN)); identifiable.addIdentifier(Identifier.createTemplate("DLN", DRIVERS_LICENSE)); }
@Test public void shouldStoreTemporaryWhenVisitTemporaryOnStoreSideOfExpression() { Identifier identifier = mock(Identifier.class); when(identifier.isOnLoadSideOfExpression()).thenReturn(false); analyser.initializeTemporariesRegistration(); analyser.temporariesRegistry().put("tmp", 1); analyser.visit(identifier, "tmp", 3); verify(writer).storeTemporary(1); }
@Test(expected = RedlineException.class) public void shouldNotAllowStoreIntoMethodOrBlockArgument() { Identifier identifier = mock(Identifier.class); when(identifier.isOnLoadSideOfExpression()).thenReturn(false); analyser.initializeBlockArgumentsRegistration(); analyser.argumentsRegistry().put("arg", 1); analyser.initializeTemporariesRegistration(); analyser.visit(identifier, "arg", 3); }
@Test public void shouldPushArgumentWhenVisitArgumentOnLoadSideOfExpression() { Identifier identifier = mock(Identifier.class); when(identifier.isOnLoadSideOfExpression()).thenReturn(true); analyser.initializeBlockArgumentsRegistration(); analyser.argumentsRegistry().put("arg", 1); analyser.visit(identifier, "arg", 3); verify(writer).pushArgument(1); }
@Override public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof ResourceBitmapLoader) || !super.equals(o)) return false; final ResourceBitmapLoader d = (ResourceBitmapLoader) o; Identifier id = (Identifier) mId; return id.equals(d.mId); }
/** * Removes this object from the object bench. This will also remove it from the view of the object * bench. Once the object is removed from the bench it will not be available again. * * @throws ProjectNotOpenException if the project to which this object belongs has been closed by * the user. * @throws PackageNotFoundException if the package to which this object belongs has been deleted * by the user. */ public void removeFromBench() throws ProjectNotOpenException, PackageNotFoundException { Package aPackage = wrapperId.getBluejPackage(); PkgMgrFrame aFrame = wrapperId.getPackageFrame(); ObjectBench aBench = aFrame.getObjectBench(); aBench.removeObject(objectWrapper, aPackage.getId()); objectWrapper = null; }
public ProjectModule getModuleForIdentifier(Identifier identifier) { final List<ProjectModule> allModules = getFlatListOfAllModules(config.getModules()); for (ProjectModule module : allModules) { if (identifier.getGroupId().equals(module.getGroupId()) && identifier.getArtifactId().equals(module.getArtifactId())) { return module; } } return null; }
private static Vector<Identifier> _s(Identifier t1, Identifier t2) { Vector<Identifier> hash = new Vector<Identifier>(); if (!t1.toString().equals("")) { hash.add(t1); } if (!t2.toString().equals("")) { hash.add(t2); } return hash; }
public Identifier getActualTaggedTypeName(TaggedTypeRef struct) { Identifier structName = null; Identifier tag = struct.getTag(); if (tag == null || tag.isPlain() && tag.toString().startsWith("_")) { TypeDef parentDef = as(struct.getParentElement(), TypeDef.class); if (parentDef != null) { structName = new Identifier.SimpleIdentifier(JNAeratorUtils.findBestPlainStorageName(parentDef)); } else if (tag != null) { String better = tag.toString().substring(1); Pair<TypeDef, Declarator> pair = result.typeDefs.get(better); if (pair != null && pair.getFirst().getValueType() != null && pair.getSecond() instanceof DirectDeclarator) { TypeRef tr = pair.getFirst().getValueType(); DirectDeclarator dd = (DirectDeclarator) pair.getSecond(); if (tr instanceof SimpleTypeRef) { if (tag.equals(((SimpleTypeRef) tr).getName())) structName = ident(dd.resolveName()); } else if (tr instanceof TaggedTypeRef) { if (tag.equals(((TaggedTypeRef) tr).getTag())) structName = ident(dd.resolveName()); } } } } if (structName == null || structName.toString().equals("")) structName = tag; return structName == null ? null : structName.clone(); }
@SuppressWarnings("unchecked") public void transformProcedure(Procedure proc) { List<ReturnStatement> ret_stmts = (new DFIterator<ReturnStatement>(proc, ReturnStatement.class)).getList(); CompoundStatement body = proc.getBody(); List ret_type = proc.getReturnType(); // Remove scope qualifiers not necessary in type resolution while (ret_type.remove(Specifier.INLINE)) ; while (ret_type.remove(Specifier.STATIC)) ; while (ret_type.remove(Specifier.EXTERN)) ; boolean ret_type_void = (ret_type.contains(Specifier.VOID) && ret_type.size() == 1); Identifier ret_id = null; // add a variable _ret_val of the same type as the procedure return type if (!ret_type_void) { // check for implicit int (TODO - differentiate this from constructors) if (ret_type.isEmpty()) { ret_type.add(Specifier.INT); } ret_id = SymbolTools.getTemp(body, ret_type, "_ret_val"); } // add a labeled return statement to the end of the procedure String done_label = "_done"; body.addStatement(new Label(new NameID(done_label))); if (!ret_type_void) { body.addStatement(new ReturnStatement(ret_id.clone())); } else { body.addStatement(new ReturnStatement()); } // redirect the preexisting return statements to the labeled return for (ReturnStatement ret_stmt : ret_stmts) { // Identify the parent compound statement. CompoundStatement comp_stmt = IRTools.getAncestorOfType(ret_stmt, CompoundStatement.class); // Add goto statement. Statement goto_stmt = new GotoStatement(new NameID(done_label)); comp_stmt.addStatementAfter(ret_stmt, goto_stmt); // Add temporary assignments. if (!ret_type_void) { Statement new_stmt = new ExpressionStatement( new AssignmentExpression( ret_id.clone(), AssignmentOperator.NORMAL, ret_stmt.getExpression().clone())); comp_stmt.addStatementBefore(goto_stmt, new_stmt); } // Remove the original return statement. comp_stmt.removeStatement(ret_stmt); // Add comments. /* CommentAnnotation info = new CommentAnnotation("Normalized Return: " + ret_stmt); info.setOneLiner(true); goto_stmt.annotateBefore(info); */ } }
protected UserDefinedFunction( Identifier function, FunctionSignature.WithValues<Object, SkylarkType> signature, ImmutableList<Statement> statements, Environment.Frame definitionGlobals) throws EvalException { super(function.getName(), signature, function.getLocation()); this.statements = statements; this.definitionGlobals = definitionGlobals; method = enableCompiler ? buildCompiledFunction() : Optional.<Method>absent(); }