How to use identifier method of end.end.end Package

Best Unobtainium_ruby code snippet using end.end.end.identifier

AbstractCommentParser.java

Source:AbstractCommentParser.java Github

copy

Full Screen

...64 protected int tagValue = NO_TAG_VALUE;65 // Line pointers66 private int linePtr, lastLinePtr;67 // Identifier stack68 protected int identifierPtr;69 protected char[][] identifierStack;70 protected int identifierLengthPtr;71 protected int[] identifierLengthStack;72 protected long[] identifierPositionStack;73 // Ast stack74 protected final static int AST_STACK_INCREMENT = 10;75 protected int astPtr;76 protected Object[] astStack;77 protected int astLengthPtr;78 protected int[] astLengthStack;79 protected AbstractCommentParser(Parser sourceParser) {80 this.sourceParser = sourceParser;81 this.scanner = new Scanner(false, false, false, ClassFileConstants.JDK1_3, null, null, true/*taskCaseSensitive*/);82 this.identifierStack = new char[20][];83 this.identifierPositionStack = new long[20];84 this.identifierLengthStack = new int[10];85 this.astStack = new Object[30];86 this.astLengthStack = new int[20];87 this.reportProblems = sourceParser != null;88 if (sourceParser != null) {89 this.checkDocComment = this.sourceParser.options.docCommentSupport;90 this.sourceLevel = this.sourceParser.options.sourceLevel;91 this.scanner.sourceLevel = this.sourceLevel;92 this.complianceLevel = this.sourceParser.options.complianceLevel;93 }94 }95 /* (non-Javadoc)96 * Returns true if tag @deprecated is present in javadoc comment.97 *98 * If javadoc checking is enabled, will also construct an Javadoc node, which will be stored into Parser.javadoc99 * slot for being consumed later on.100 */101 protected boolean commentParse() {102 boolean validComment = true;103 try {104 // Init scanner position105 this.linePtr = getLineNumber(this.firstTagPosition);106 int realStart = this.linePtr==1 ? javadocStart : this.scanner.getLineEnd(this.linePtr-1)+1;107 if (realStart < javadocStart) realStart = javadocStart;108 this.scanner.resetTo(realStart, javadocEnd);109 this.index = realStart;110 if (realStart == javadocStart) {111 readChar(); // starting '/'112 readChar(); // first '*'113 }114 int previousPosition = this.index;115 char nextCharacter = 0;116 if (realStart == javadocStart) nextCharacter = readChar(); // second '*'117 // Init local variables118 this.astLengthPtr = -1;119 this.astPtr = -1;120 this.identifierPtr = -1;121 this.currentTokenType = -1;122 this.inlineTagStarted = false;123 this.inlineTagStart = -1;124 this.lineStarted = false;125 this.returnStatement = null;126 this.inheritedPositions = -1;127 this.deprecated = false;128 this.lastLinePtr = getLineNumber(javadocEnd);129 this.lineEnd = (this.linePtr == this.lastLinePtr) ? this.javadocEnd: this.scanner.getLineEnd(this.linePtr) - 1;130 this.textStart = -1;131 char previousChar = 0;132 int invalidTagLineEnd = -1;133 int invalidInlineTagLineEnd = -1;134 boolean pushText = (this.kind & TEXT_PARSE) != 0;135 boolean verifText = (this.kind & TEXT_VERIF) != 0;136 boolean isDomParser = (this.kind & DOM_PARSER) != 0;137 // Loop on each comment character138 while (!abort && this.index < this.javadocEnd) {139 previousPosition = this.index;140 previousChar = nextCharacter;141 // Calculate line end (cannot use this.scanner.linePtr as scanner does not parse line ends again)142 if (this.index > (this.lineEnd+1)) {143 updateLineEnd();144 }145 // Read next char only if token was consumed146 if (this.currentTokenType < 0) {147 nextCharacter = readChar(); // consider unicodes148 } else {149 previousPosition = this.scanner.getCurrentTokenStartPosition();150 switch (this.currentTokenType) {151 case TerminalTokens.TokenNameRBRACE:152 nextCharacter = '}';153 break;154 case TerminalTokens.TokenNameMULTIPLY:155 nextCharacter = '*';156 break;157 default:158 nextCharacter = this.scanner.currentCharacter;159 }160 consumeToken();161 }162 if (this.index >= this.javadocEnd) {163 break;164 }165 switch (nextCharacter) {166 case '@' :167 // Start tag parsing only if we are on line beginning or at inline tag beginning168 if ((!this.lineStarted || previousChar == '{')) {169 if (this.inlineTagStarted) {170 this.inlineTagStarted = false;171 // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=53279172 // Cannot have @ inside inline comment173 if (this.reportProblems) {174 int end = previousPosition<invalidInlineTagLineEnd ? previousPosition : invalidInlineTagLineEnd;175 this.sourceParser.problemReporter().javadocUnterminatedInlineTag(this.inlineTagStart, end);176 }177 validComment = false;178 if (this.textStart != -1 && this.textStart < previousPosition) {179 if (pushText) pushText(this.textStart, previousPosition);180 }181 if (isDomParser) refreshInlineTagPosition(previousPosition);182 }183 if (previousChar == '{') {184 if (this.textStart != -1 && this.textStart < this.inlineTagStart) {185 if (pushText) pushText(this.textStart, this.inlineTagStart);186 }187 this.inlineTagStarted = true;188 invalidInlineTagLineEnd = this.lineEnd;189 } else if (this.textStart != -1 && this.textStart < invalidTagLineEnd) {190 if (pushText) pushText(this.textStart, invalidTagLineEnd);191 }192 this.scanner.resetTo(this.index, this.javadocEnd);193 this.currentTokenType = -1; // flush token cache at line begin194 try {195 if (!parseTag(previousPosition)) {196 // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=51600197 // do not stop the inline tag when error is encountered to get text after198 validComment = false;199 // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=51600200 // for DOM AST node, store tag as text in case of invalid syntax201 if (isDomParser) {202 createTag();203 }204 this.textStart = this.tagSourceEnd+1;205 invalidTagLineEnd = this.lineEnd;206 }207 } catch (InvalidInputException e) {208 consumeToken();209 }210 } else if (verifText && (this.tagValue == TAG_RETURN_VALUE || this.tagValue == TAG_RETURNS_VALUE) && this.returnStatement != null) {211 refreshReturnStatement();212 }213 this.lineStarted = true;214 break;215 case '\r':216 case '\n':217 if (this.lineStarted && this.textStart < previousPosition) {218 if (pushText) pushText(this.textStart, previousPosition);219 }220 this.lineStarted = false;221 // Fix bug 51650222 this.textStart = -1;223 break;224 case '}' :225 if (verifText && (this.tagValue == TAG_RETURN_VALUE || this.tagValue == TAG_RETURNS_VALUE) && this.returnStatement != null) {226 refreshReturnStatement();227 }228 if (this.inlineTagStarted) {229 if (pushText) {230 if (this.lineStarted && this.textStart != -1 && this.textStart < previousPosition) {231 pushText(this.textStart, previousPosition);232 }233 refreshInlineTagPosition(previousPosition);234 }235 this.textStart = this.index;236 this.inlineTagStarted = false;237 } else {238 if (!this.lineStarted) {239 this.textStart = previousPosition;240 }241 }242 this.lineStarted = true;243 break;244 case '{' :245 if (verifText && (this.tagValue == TAG_RETURN_VALUE || this.tagValue == TAG_RETURNS_VALUE) && this.returnStatement != null) {246 refreshReturnStatement();247 }248 if (this.inlineTagStarted) {249 this.inlineTagStarted = false;250 // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=53279251 // Cannot have opening brace in inline comment252 if (this.reportProblems) {253 int end = previousPosition<invalidInlineTagLineEnd ? previousPosition : invalidInlineTagLineEnd;254 this.sourceParser.problemReporter().javadocUnterminatedInlineTag(this.inlineTagStart, end);255 }256 if (pushText) {257 if (this.lineStarted && this.textStart != -1 && this.textStart < previousPosition) {258 pushText(this.textStart, previousPosition);259 }260 refreshInlineTagPosition(previousPosition);261 }262 }263 if (!this.lineStarted) {264 this.textStart = previousPosition;265 }266 this.lineStarted = true;267 this.inlineTagStart = previousPosition;268 break;269 case '*' :270 case '\u000c' : /* FORM FEED */271 case ' ' : /* SPACE */272 case '\t' : /* HORIZONTAL TABULATION */273 // do nothing for space or '*' characters274 break;275 default :276 if (verifText && (this.tagValue == TAG_RETURN_VALUE || this.tagValue == TAG_RETURNS_VALUE) && this.returnStatement != null) {277 refreshReturnStatement();278 }279 if (!this.lineStarted) {280 this.textStart = previousPosition;281 }282 this.lineStarted = true;283 break;284 }285 }286 // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=53279287 // Cannot leave comment inside inline comment288 if (this.inlineTagStarted) {289 this.inlineTagStarted = false;290 if (this.reportProblems) {291 int end = previousPosition<invalidInlineTagLineEnd ? previousPosition : invalidInlineTagLineEnd;292 if (this.index >= this.javadocEnd) end = invalidInlineTagLineEnd;293 this.sourceParser.problemReporter().javadocUnterminatedInlineTag(this.inlineTagStart, end);294 }295 if (pushText) {296 if (this.lineStarted && this.textStart != -1 && this.textStart < previousPosition) {297 pushText(this.textStart, previousPosition);298 }299 refreshInlineTagPosition(previousPosition);300 }301 } else if (pushText && this.lineStarted && this.textStart < previousPosition) {302 pushText(this.textStart, previousPosition);303 }304 updateDocComment();305 } catch (Exception ex) {306 validComment = false;307 }308 return validComment;309 }310 protected void consumeToken() {311 this.currentTokenType = -1; // flush token cache312 updateLineEnd();313 }314 protected abstract Object createArgumentReference(char[] name, int dim, boolean isVarargs, Object typeRef, long[] dimPos, long argNamePos) throws InvalidInputException;315 protected abstract Object createFieldReference(Object receiver) throws InvalidInputException;316 protected abstract Object createMethodReference(Object receiver, List arguments) throws InvalidInputException;317 protected Object createReturnStatement() { return null; }318 protected abstract void createTag();319 protected abstract Object createTypeReference(int primitiveToken);320 /**321 * Search the line number corresponding to a specific position.322 * Warning: returned position is 1-based index!323 * @see Scanner#getLineNumber(int) We cannot directly use this method324 * when linePtr field is not initialized.325 */326 private int getLineNumber(int position) {327 if (this.scanner.linePtr != -1) {328 return Util.getLineNumber(position, this.scanner.lineEnds, 0, this.scanner.linePtr);329 }330 if (this.lineEnds == null)331 return 1;332 return Util.getLineNumber(position, this.lineEnds, 0, this.lineEnds.length-1);333 }334 private int getTokenEndPosition() {335 if (this.scanner.getCurrentTokenEndPosition() > this.lineEnd) {336 return this.lineEnd;337 } else {338 return this.scanner.getCurrentTokenEndPosition();339 }340 }341 /**342 * @return Returns the currentTokenType.343 */344 protected int getCurrentTokenType() {345 return currentTokenType;346 }347 /*348 * Parse argument in @see tag method reference349 */350 protected Object parseArguments(Object receiver) throws InvalidInputException {351 // Init352 int modulo = 0; // should be 2 for (Type,Type,...) or 3 for (Type arg,Type arg,...)353 int iToken = 0;354 char[] argName = null;355 List arguments = new ArrayList(10);356 int start = this.scanner.getCurrentTokenStartPosition();357 Object typeRef = null;358 int dim = 0;359 boolean isVarargs = false;360 long[] dimPositions = new long[20]; // assume that there won't be more than 20 dimensions...361 char[] name = null;362 long argNamePos = -1;363 // Parse arguments declaration if method reference364 nextArg : while (this.index < this.scanner.eofPosition) {365 // Read argument type reference366 try {367 typeRef = parseQualifiedName(false);368 if (this.abort) return null; // May be aborted by specialized parser369 } catch (InvalidInputException e) {370 break nextArg;371 }372 boolean firstArg = modulo == 0;373 if (firstArg) { // verify position374 if (iToken != 0)375 break nextArg;376 } else if ((iToken % modulo) != 0) {377 break nextArg;378 }379 if (typeRef == null) {380 if (firstArg && this.currentTokenType == TerminalTokens.TokenNameRPAREN) {381 // verify characters after arguments declaration (expecting white space or end comment)382 if (!verifySpaceOrEndComment()) {383 int end = this.starPosition == -1 ? this.lineEnd : this.starPosition;384 if (this.source[end]=='\n') end--;385 if (this.reportProblems) this.sourceParser.problemReporter().javadocMalformedSeeReference(start, end);386 return null;387 }388 this.lineStarted = true;389 return createMethodReference(receiver, null);390 }391 break nextArg;392 }393 iToken++;394 // Read possible additional type info395 dim = 0;396 isVarargs = false;397 if (readToken() == TerminalTokens.TokenNameLBRACKET) {398 // array declaration399 int dimStart = this.scanner.getCurrentTokenStartPosition();400 while (readToken() == TerminalTokens.TokenNameLBRACKET) {401 consumeToken();402 if (readToken() != TerminalTokens.TokenNameRBRACKET) {403 break nextArg;404 }405 consumeToken();406 dimPositions[dim++] = (((long) dimStart) << 32) + this.scanner.getCurrentTokenEndPosition();407 }408// } else if (readToken() == TerminalTokens.TokenNameELLIPSIS) {409// // ellipsis declaration410// int dimStart = this.scanner.getCurrentTokenStartPosition();411// dimPositions[dim++] = (((long) dimStart) << 32) + this.scanner.getCurrentTokenEndPosition();412// consumeToken();413// isVarargs = true;414 }415 // Read argument name416 argNamePos = -1;417 if (readToken() == TerminalTokens.TokenNameIdentifier) {418 consumeToken();419 if (firstArg) { // verify position420 if (iToken != 1)421 break nextArg;422 } else if ((iToken % modulo) != 1) {423 break nextArg;424 }425 if (argName == null) { // verify that all arguments name are declared426 if (!firstArg) {427 break nextArg;428 }429 }430 argName = this.scanner.getCurrentIdentifierSource();431 argNamePos = (((long)this.scanner.getCurrentTokenStartPosition())<<32)+this.scanner.getCurrentTokenEndPosition();432 iToken++;433 } else if (argName != null) { // verify that no argument name is declared434 break nextArg;435 }436 // Verify token position437 if (firstArg) {438 modulo = iToken + 1;439 } else {440 if ((iToken % modulo) != (modulo - 1)) {441 break nextArg;442 }443 }444 // Read separator or end arguments declaration445 int token = readToken();446 name = argName == null ? CharOperation.NO_CHAR : argName;447 if (token == TerminalTokens.TokenNameCOMMA) {448 // Create new argument449 Object argument = createArgumentReference(name, dim, isVarargs, typeRef, dimPositions, argNamePos);450 if (this.abort) return null; // May be aborted by specialized parser451 arguments.add(argument);452 consumeToken();453 iToken++;454 } else if (token == TerminalTokens.TokenNameRPAREN) {455 // verify characters after arguments declaration (expecting white space or end comment)456 if (!verifySpaceOrEndComment()) {457 int end = this.starPosition == -1 ? this.lineEnd : this.starPosition;458 if (this.source[end]=='\n') end--;459 if (this.reportProblems) this.sourceParser.problemReporter().javadocMalformedSeeReference(start, end);460 return null;461 }462 // Create new argument463 Object argument = createArgumentReference(name, dim, isVarargs, typeRef, dimPositions, argNamePos);464 if (this.abort) return null; // May be aborted by specialized parser465 arguments.add(argument);466 consumeToken();467 return createMethodReference(receiver, arguments);468 } else {469 break nextArg;470 }471 }472 // Something wrong happened => Invalid input473 throw new InvalidInputException();474 }475 /*476 * Parse an URL link reference in @see tag477 */478 private boolean parseHref() throws InvalidInputException {479 int start = this.scanner.getCurrentTokenStartPosition();480 char currentChar = readChar();481 if (currentChar == 'a' || currentChar == 'A') {482 this.scanner.currentPosition = this.index;483 if (readToken() == TerminalTokens.TokenNameIdentifier) {484 consumeToken();485 try {486 if (CharOperation.equals(this.scanner.getCurrentIdentifierSource(), new char[]{'h', 'r', 'e', 'f'}, false) &&487 readToken() == TerminalTokens.TokenNameEQUAL) {488 consumeToken();489 if (readToken() == TerminalTokens.TokenNameStringLiteral) {490 consumeToken();491 // Skip all characters after string literal until closing '>' (see bug 68726)492 while (readToken() != TerminalTokens.TokenNameGREATER) {493 if (this.scanner.currentPosition >= this.scanner.eofPosition || this.scanner.currentCharacter == '@' ||494 (this.inlineTagStarted && this.scanner.currentCharacter == '}')) {495 // Reset position: we want to rescan last token496 this.index = this.tokenPreviousPosition;497 this.scanner.currentPosition = this.tokenPreviousPosition;498 this.currentTokenType = -1;499 // Signal syntax error500 if (this.reportProblems) this.sourceParser.problemReporter().javadocInvalidSeeUrlReference(start, this.lineEnd);501 502 return false;503 }504 this.currentTokenType = -1; // do not update line end505 }506 if (this.currentTokenType == TerminalTokens.TokenNameGREATER) {507 consumeToken(); // update line end as new lines are allowed in URL description508 while (readToken() != TerminalTokens.TokenNameLESS) {509 if (this.scanner.currentPosition >= this.scanner.eofPosition || this.scanner.currentCharacter == '@' ||510 (this.inlineTagStarted && this.scanner.currentCharacter == '}')) {511 // Reset position: we want to rescan last token512 this.index = this.tokenPreviousPosition;513 this.scanner.currentPosition = this.tokenPreviousPosition;514 this.currentTokenType = -1;515 // Signal syntax error516 if (this.reportProblems) this.sourceParser.problemReporter().javadocInvalidSeeUrlReference(start, this.lineEnd);517 518 return false;519 }520 consumeToken();521 }522 consumeToken();523 start = this.scanner.getCurrentTokenStartPosition();524 if (readChar() == '/') {525 currentChar = readChar();526 if (currentChar == 'a' || currentChar == 'A') {527 if (readChar() == '>') {528 // Valid href529 return true;530 }531 }532 }533 }534 }535 }536 } catch (InvalidInputException ex) {537 // Do nothing as we want to keep positions for error message538 }539 }540 }541 // Reset position: we want to rescan last token542 this.index = this.tokenPreviousPosition;543 this.scanner.currentPosition = this.tokenPreviousPosition;544 this.currentTokenType = -1;545 // Signal syntax error546 if (this.reportProblems) this.sourceParser.problemReporter().javadocInvalidSeeUrlReference(start, this.lineEnd);547 548 return false;549 }550 /*551 * Parse tag followed by an identifier552 */553 protected boolean parseIdentifierTag(boolean report) {554 int token = readTokenSafely();555 switch (token) {556 case TerminalTokens.TokenNameIdentifier:557 pushIdentifier(true, false);558 return true;559 }560 if (report) {561 this.sourceParser.problemReporter().javadocMissingIdentifier(this.tagSourceStart, this.tagSourceEnd, this.sourceParser.modifiers);562 }563 return false;564 }565 /*566 * Parse a method reference in @see tag567 */568 protected Object parseMember(Object receiver) throws InvalidInputException {569 // Init570 this.identifierPtr = -1;571 this.identifierLengthPtr = -1;572 int start = this.scanner.getCurrentTokenStartPosition();573 this.memberStart = start;574 // Get member identifier575 if (readToken() == TerminalTokens.TokenNameIdentifier) {576 if (this.scanner.currentCharacter == '.') { // member name may be qualified (inner class constructor reference)577 parseQualifiedName(true);578 } else {579 consumeToken();580 pushIdentifier(true, false);581 }582 // Look for next token to know whether it's a field or method reference583 int previousPosition = this.index;584 if (readToken() == TerminalTokens.TokenNameLPAREN) {585 consumeToken();586 start = this.scanner.getCurrentTokenStartPosition();587 try {588 return parseArguments(receiver);589 } catch (InvalidInputException e) {590 int end = this.scanner.getCurrentTokenEndPosition() < this.lineEnd ?591 this.scanner.getCurrentTokenEndPosition() :592 this.scanner.getCurrentTokenStartPosition();593 end = end < this.lineEnd ? end : this.lineEnd;594 if (this.reportProblems) this.sourceParser.problemReporter().javadocInvalidSeeReferenceArgs(start, end);595 }596 return null;597 }598 // Reset position: we want to rescan last token599 this.index = previousPosition;600 this.scanner.currentPosition = previousPosition;601 this.currentTokenType = -1;602 // Verify character(s) after identifier (expecting space or end comment)603 if (!verifySpaceOrEndComment()) {604 int end = this.starPosition == -1 ? this.lineEnd : this.starPosition;605 if (this.source[end]=='\n') end--;606 if (this.reportProblems) this.sourceParser.problemReporter().javadocMalformedSeeReference(start, end);607 return null;608 }609 return createFieldReference(receiver);610 }611 int end = getTokenEndPosition() - 1;612 end = start > end ? start : end;613 if (this.reportProblems) this.sourceParser.problemReporter().javadocInvalidReference(start, end);614 // Reset position: we want to rescan last token615 this.index = this.tokenPreviousPosition;616 this.scanner.currentPosition = this.tokenPreviousPosition;617 this.currentTokenType = -1;618 return null;619 }620 /*621 * Parse @param tag declaration622 */623 protected boolean parseParam() throws InvalidInputException {624 // Store current state625 int start = this.tagSourceStart;626 int end = this.tagSourceEnd;627 boolean tokenWhiteSpace = this.scanner.tokenizeWhiteSpace;628 this.scanner.tokenizeWhiteSpace = true;629 Object []typeReference=null;630 // Verify that there are whitespaces after tag631 boolean isCompletionParser = (this.kind & COMPLETION_PARSER) != 0;632 if (this.scanner.currentCharacter != ' ' && !ScannerHelper.isWhitespace(this.scanner.currentCharacter)) {633 if (this.reportProblems) this.sourceParser.problemReporter().javadocInvalidTag(start, this.scanner.getCurrentTokenEndPosition());634 if (!isCompletionParser) {635 this.scanner.currentPosition = start;636 this.index = start;637 }638 this.currentTokenType = -1;639 this.scanner.tokenizeWhiteSpace = tokenWhiteSpace;640 return false;641 }642 // Get first non whitespace token643 this.identifierPtr = -1;644 this.identifierLengthPtr = -1;645 boolean hasMultiLines = this.scanner.currentPosition > (this.lineEnd+1);646 boolean valid = true, empty = true;647 boolean isParmType=false;648 int token = -1;649 nextToken: while (true) {650 this.currentTokenType = -1;651 try {652 token = readToken();653 } catch (InvalidInputException e) {654 valid = false;655 }656 switch (token) {657 case TerminalTokens.TokenNameIdentifier :658 if (valid) {659 // store param name id660 pushIdentifier(true, false);661 start = this.scanner.getCurrentTokenStartPosition();662 end = hasMultiLines ? this.lineEnd: this.scanner.getCurrentTokenEndPosition();663 break nextToken;664 }665 // fall through next case to report error666 default:667 if (valid && !hasMultiLines) start = this.scanner.getCurrentTokenStartPosition();668 valid = false;669 if (!hasMultiLines) {670 empty = false;671 end = hasMultiLines ? this.lineEnd: this.scanner.getCurrentTokenEndPosition();672 break;673 }674 end = this.lineEnd;675 // when several lines, fall through next case to report problem immediately676 case TerminalTokens.TokenNameWHITESPACE:677 if (this.scanner.currentPosition > (this.lineEnd+1)) hasMultiLines = true;678 if (valid) break;679 // if not valid fall through next case to report error680 case TerminalTokens.TokenNameEOF:681 if (this.reportProblems)682 if (empty)683 this.sourceParser.problemReporter().javadocMissingParamName(start, end, this.sourceParser.modifiers);684 else685 this.sourceParser.problemReporter().javadocInvalidParamTagName(start, end);686 if (!isCompletionParser) {687 this.scanner.currentPosition = start;688 this.index = start;689 }690 this.currentTokenType = -1;691 this.scanner.tokenizeWhiteSpace = tokenWhiteSpace;692 return false;693 case TerminalTokens.TokenNameLBRACE:694 this.scanner.tokenizeWhiteSpace = false;695 typeReference=parseTypeReference();696 isParmType=true;697 this.identifierPtr = -1;698 this.identifierLengthPtr = -1;699 this.scanner.tokenizeWhiteSpace = true;700 break;701 }702 }703 // Verify that tag name is well followed by white spaces704 if (valid) {705 this.currentTokenType = -1;706 int restart = this.scanner.currentPosition;707 try {708 token = readToken();709 } catch (InvalidInputException e) {710 valid = false;711 }712 if (token == TerminalTokens.TokenNameWHITESPACE) {713 this.scanner.currentPosition = restart;714 this.index = restart;715 this.scanner.tokenizeWhiteSpace = tokenWhiteSpace;716 valid= pushParamName(false);717 if (valid && isParmType )718 {719 createParamType(typeReference);720 }721 return valid;722 }723 }724 // Report problem725 this.currentTokenType = -1;726 if (isCompletionParser) return false;727 end = hasMultiLines ? this.lineEnd: this.scanner.getCurrentTokenEndPosition();728 while ((token=readToken()) != TerminalTokens.TokenNameWHITESPACE && token != TerminalTokens.TokenNameEOF) {729 this.currentTokenType = -1;730 end = hasMultiLines ? this.lineEnd: this.scanner.getCurrentTokenEndPosition();731 }732 if (this.reportProblems)733 this.sourceParser.problemReporter().javadocInvalidParamTagName(start, end);734 this.scanner.currentPosition = start;735 this.index = start;736 this.currentTokenType = -1;737 this.scanner.tokenizeWhiteSpace = tokenWhiteSpace;738 return false;739 }740 protected abstract void createParamType(Object[] typeReference) ;741 protected Object [] parseTypeReference() {742 int currentPosition = this.scanner.currentPosition;743 try {744 ArrayList typeRefs = new ArrayList();745// Object reference = null;746// int previousPosition = -1;747// int typeRefStartPosition = -1;748 boolean expectingRef=true;749 // Get reference tokens750 nextToken : while (this.index < this.scanner.eofPosition ) {751// previousPosition = this.index;752 int token = readTokenSafely();753 switch (token) {754 case TerminalTokens.TokenNameRBRACE :755 // If typeRef != null we may raise a warning here to let user know there's an unused reference...756 // Currently as javadoc 1.4.2 ignore it, we do the same (see bug 69302)757 consumeToken();758 break nextToken;759 case TerminalTokens.TokenNameLBRACE :760 // If typeRef != null we may raise a warning here to let user know there's an unused reference...761 // Currently as javadoc 1.4.2 ignore it, we do the same (see bug 69302)762 consumeToken();763 break ;764 case TerminalTokens.TokenNameLESS : // @see "<a href="URL#Value">label</a>765 // If typeRef != null we may raise a warning here to let user know there's an unused reference...766 // Currently as javadoc 1.4.2 ignore it, we do the same (see bug 69302)767// if (typeRef != null) break nextToken;768 if (!expectingRef)769 return null;770 consumeToken();771 int start = this.scanner.getCurrentTokenStartPosition();772 if (parseHref()) {773 consumeToken();774 // verify end line775// if (verifyEndLine(previousPosition))776// return true;777// if (this.reportProblems) this.sourceParser.problemReporter().javadocUnexpectedText(this.scanner.currentPosition, this.lineEnd);778 }779 expectingRef=false;780 break;781 case TerminalTokens.TokenNameERROR :782 consumeToken();783 char[] currentError = this.scanner.getCurrentIdentifierSource();784 if (currentError.length>0 && currentError[0] == '"') {785 if (this.reportProblems) this.sourceParser.problemReporter().javadocInvalidReference(this.scanner.getCurrentTokenStartPosition(), getTokenEndPosition());786 return null;787 }788 break nextToken;789 case TerminalTokens.TokenNameIdentifier :790 if (!expectingRef)791 return null;792// typeRefStartPosition = this.scanner.getCurrentTokenStartPosition();793 Object ref = parseQualifiedName(true);794 if (ref!=null)795 typeRefs.add(ref);796 expectingRef=false;797 if (this.abort) return null; // May be aborted by specialized parser798 break;799 case TerminalTokens.TokenNameOR :800 if (expectingRef)801 return null;802 consumeToken();803 expectingRef=true;804 break;805 default :806 break nextToken;807 }808 }809 if (typeRefs.isEmpty()) {810 this.index = this.tokenPreviousPosition;811 this.scanner.currentPosition = this.tokenPreviousPosition;812 this.currentTokenType = -1;813 if (this.reportProblems) {814 this.sourceParser.problemReporter().javadocMissingReference(this.tagSourceStart, this.tagSourceEnd, this.sourceParser.modifiers);815 }816 return null;817 }818 this.currentTokenType = -1;819 Object[] typeReferences=typeRefs.toArray();820 return typeReferences;821 }822 catch (InvalidInputException ex) {823 if (this.reportProblems) this.sourceParser.problemReporter().javadocInvalidReference(currentPosition, getTokenEndPosition());824 }825 // Reset position to avoid missing tokens when new line was encountered826 this.index = this.tokenPreviousPosition;827 this.scanner.currentPosition = this.tokenPreviousPosition;828 this.currentTokenType = -1;829 return null;830 }831 /*832 * Parse a qualified name and built a type reference if the syntax is valid.833 */834 protected Object parseQualifiedName(boolean reset) throws InvalidInputException {835 boolean tokenizeWhiteSpace=this.scanner.tokenizeWhiteSpace;836 this.scanner.tokenizeWhiteSpace=false;837 try {838 // Reset identifier stack if requested839 if (reset) {840 this.identifierPtr = -1;841 this.identifierLengthPtr = -1;842 }843 // Scan tokens844 int primitiveToken = -1;845 int parserKind = this.kind & PARSER_KIND;846 nextToken: for (int iToken = 0;; iToken++) {847 int token = readTokenSafely();848 switch (token) {849 case TerminalTokens.TokenNameIdentifier:850 if (((iToken & 1) != 0)) { // identifiers must be odd tokens851 break nextToken;852 }853 pushIdentifier(iToken == 0, false);854 consumeToken();855 break;856 case TerminalTokens.TokenNameDOT:857 if ((iToken & 1) == 0) { // dots must be even tokens858 throw new InvalidInputException();859 }860 consumeToken();861 break;862 case TerminalTokens.TokenNamevoid:863 case TerminalTokens.TokenNameboolean:864 case TerminalTokens.TokenNamebyte:865 case TerminalTokens.TokenNamechar:866 case TerminalTokens.TokenNamedouble:867 case TerminalTokens.TokenNamefloat:868 case TerminalTokens.TokenNameint:869 case TerminalTokens.TokenNamelong:870 case TerminalTokens.TokenNameshort:871 if (iToken > 0) {872 throw new InvalidInputException();873 }874 pushIdentifier(true, false);875 primitiveToken = token;876 consumeToken();877 break nextToken;878 default:879 if (iToken == 0) {880 if (this.identifierPtr >= 0) {881 this.lastIdentifierEndPosition = (int) this.identifierPositionStack[this.identifierPtr];882 }883 return null;884 }885 if ((iToken & 1) == 0) { // cannot leave on a dot886 switch (parserKind) {887 case COMPLETION_PARSER:888 if (this.identifierPtr >= 0) {889 this.lastIdentifierEndPosition = (int) this.identifierPositionStack[this.identifierPtr];890 }891 return syntaxRecoverQualifiedName(primitiveToken);892 case DOM_PARSER:893 if (this.currentTokenType != -1) {894 // Reset position: we want to rescan last token895 this.index = this.tokenPreviousPosition;896 this.scanner.currentPosition = this.tokenPreviousPosition;897 this.currentTokenType = -1;898 }899 // fall through default case to raise exception900 default:901 throw new InvalidInputException();902 }903 }904 break nextToken;905 }906 }907 // Reset position: we want to rescan last token908 if (parserKind != COMPLETION_PARSER && this.currentTokenType != -1) {909 this.index = this.tokenPreviousPosition;910 this.scanner.currentPosition = this.tokenPreviousPosition;911 this.currentTokenType = -1;912 }913 if (this.identifierPtr >= 0) {914 this.lastIdentifierEndPosition = (int) this.identifierPositionStack[this.identifierPtr];915 }916 return createTypeReference(primitiveToken);917 } finally {918 this.scanner.tokenizeWhiteSpace=tokenizeWhiteSpace;919 }920 }921 /*922 * Parse a reference in @see tag923 */924 protected boolean parseReference() throws InvalidInputException {925 int currentPosition = this.scanner.currentPosition;926 try {927 Object typeRef = null;928 Object reference = null;929 int previousPosition = -1;930 int typeRefStartPosition = -1;931 // Get reference tokens932 nextToken : while (this.index < this.scanner.eofPosition) {933 previousPosition = this.index;934 int token = readTokenSafely();935 switch (token) {936 case TerminalTokens.TokenNameStringLiteral : // @see "string"937 // If typeRef != null we may raise a warning here to let user know there's an unused reference...938 // Currently as javadoc 1.4.2 ignore it, we do the same (see bug 69302)939 if (typeRef != null) break nextToken;940 consumeToken();941 int start = this.scanner.getCurrentTokenStartPosition();942 // verify end line943 if (verifyEndLine(previousPosition)) {944 return true;945 }946 if (this.reportProblems) this.sourceParser.problemReporter().javadocUnexpectedText(this.scanner.currentPosition, this.lineEnd);947 return false;948 case TerminalTokens.TokenNameLESS : // @see "<a href="URL#Value">label</a>949 // If typeRef != null we may raise a warning here to let user know there's an unused reference...950 // Currently as javadoc 1.4.2 ignore it, we do the same (see bug 69302)951 if (typeRef != null) break nextToken;952 consumeToken();953 start = this.scanner.getCurrentTokenStartPosition();954 if (parseHref()) {955 consumeToken();956 // verify end line957 if (verifyEndLine(previousPosition)) return true;958 if (this.reportProblems) this.sourceParser.problemReporter().javadocUnexpectedText(this.scanner.currentPosition, this.lineEnd);959 }960 return false;961 case TerminalTokens.TokenNameERROR :962 consumeToken();963 if (this.scanner.currentCharacter == '#') { // @see ...#member964 reference = parseMember(typeRef);965 if (reference != null) {966 return pushSeeRef(reference);967 }968 return false;969 }970 char[] currentError = this.scanner.getCurrentIdentifierSource();971 if (currentError.length>0 && currentError[0] == '"') {972 if (this.reportProblems) this.sourceParser.problemReporter().javadocInvalidReference(this.scanner.getCurrentTokenStartPosition(), getTokenEndPosition());973 return false;974 }975 break nextToken;976 case TerminalTokens.TokenNameIdentifier :977 if (typeRef == null) {978 typeRefStartPosition = this.scanner.getCurrentTokenStartPosition();979 typeRef = parseQualifiedName(true);980 if (this.abort) return false; // May be aborted by specialized parser981 break;982 }983 default :984 break nextToken;985 }986 }987 // Verify that we got a reference988 if (reference == null) reference = typeRef;989 if (reference == null) {990 this.index = this.tokenPreviousPosition;991 this.scanner.currentPosition = this.tokenPreviousPosition;992 this.currentTokenType = -1;993 if (this.reportProblems) {994 this.sourceParser.problemReporter().javadocMissingReference(this.tagSourceStart, this.tagSourceEnd, this.sourceParser.modifiers);995 }996 return false;997 }998 // Reset position at the end of type reference999 if (this.lastIdentifierEndPosition > this.javadocStart) {1000 this.index = this.lastIdentifierEndPosition+1;1001 this.scanner.currentPosition = this.index;1002 }1003 this.currentTokenType = -1;1004 // Verify that line end does not start with an open parenthese (which could be a constructor reference wrongly written...)1005 // See bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=472151006 char ch = peekChar();1007 if (ch == '(') {1008 if (this.reportProblems) this.sourceParser.problemReporter().javadocMissingHashCharacter(typeRefStartPosition, this.lineEnd, String.valueOf(this.source, typeRefStartPosition, this.lineEnd-typeRefStartPosition+1));1009 return false;1010 }1011 // Verify that we get white space after reference1012 if (!verifySpaceOrEndComment()) {1013 this.index = this.tokenPreviousPosition;1014 this.scanner.currentPosition = this.tokenPreviousPosition;1015 this.currentTokenType = -1;1016 int end = this.starPosition == -1 ? this.lineEnd : this.starPosition;1017 if (this.source[end]=='\n') end--;1018 if (this.reportProblems) this.sourceParser.problemReporter().javadocMalformedSeeReference(typeRefStartPosition, end);1019 return false;1020 }1021 // Everything is OK, store reference1022 return pushSeeRef(reference);1023 }1024 catch (InvalidInputException ex) {1025 if (this.reportProblems) this.sourceParser.problemReporter().javadocInvalidReference(currentPosition, getTokenEndPosition());1026 }1027 // Reset position to avoid missing tokens when new line was encountered1028 this.index = this.tokenPreviousPosition;1029 this.scanner.currentPosition = this.tokenPreviousPosition;1030 this.currentTokenType = -1;1031 return false;1032 }1033 /*1034 * Parse tag declaration1035 */1036 protected abstract boolean parseTag(int previousPosition) throws InvalidInputException;1037 /*1038 * Parse @throws tag declaration1039 */1040 protected boolean parseThrows() {1041 int start = this.scanner.currentPosition;1042 try {1043 Object typeRef = parseQualifiedName(true);1044 if (this.abort) return false; // May be aborted by specialized parser1045 if (typeRef == null) {1046 if (this.reportProblems)1047 this.sourceParser.problemReporter().javadocMissingThrowsClassName(this.tagSourceStart, this.tagSourceEnd, this.sourceParser.modifiers);1048 } else {1049 return pushThrowName(typeRef);1050 }1051 } catch (InvalidInputException ex) {1052 if (this.reportProblems) this.sourceParser.problemReporter().javadocInvalidThrowsClass(start, getTokenEndPosition());1053 }1054 return false;1055 }1056 /*1057 * Return current character without move index position.1058 */1059 protected char peekChar() {1060 int idx = this.index;1061 char c = this.source[idx++];1062 if (c == '\\' && this.source[idx] == 'u') {1063 int c1, c2, c3, c4;1064 idx++;1065 while (this.source[idx] == 'u')1066 idx++;1067 if (!(((c1 = ScannerHelper.getNumericValue(this.source[idx++])) > 15 || c1 < 0)1068 || ((c2 = ScannerHelper.getNumericValue(this.source[idx++])) > 15 || c2 < 0)1069 || ((c3 = ScannerHelper.getNumericValue(this.source[idx++])) > 15 || c3 < 0) || ((c4 = ScannerHelper.getNumericValue(this.source[idx++])) > 15 || c4 < 0))) {1070 c = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);1071 }1072 }1073 return c;1074 }1075 /*1076 * push the consumeToken on the identifier stack. Increase the total number of identifier in the stack.1077 */1078 protected void pushIdentifier(boolean newLength, boolean isToken) {1079 int stackLength = this.identifierStack.length;1080 if (++this.identifierPtr >= stackLength) {1081 System.arraycopy(1082 this.identifierStack, 0,1083 this.identifierStack = new char[stackLength + 10][], 0,1084 stackLength);1085 System.arraycopy(1086 this.identifierPositionStack, 0,1087 this.identifierPositionStack = new long[stackLength + 10], 0,1088 stackLength);1089 }1090 this.identifierStack[this.identifierPtr] = isToken ? this.scanner.getCurrentTokenSource() : this.scanner.getCurrentIdentifierSource();1091 this.identifierPositionStack[this.identifierPtr] = (((long) this.scanner.startPosition) << 32) + (this.scanner.currentPosition - 1);1092 if (newLength) {1093 stackLength = this.identifierLengthStack.length;1094 if (++this.identifierLengthPtr >= stackLength) {1095 System.arraycopy(1096 this.identifierLengthStack, 0,1097 this.identifierLengthStack = new int[stackLength + 10], 0,1098 stackLength);1099 }1100 this.identifierLengthStack[this.identifierLengthPtr] = 1;1101 } else {1102 this.identifierLengthStack[this.identifierLengthPtr]++;1103 }1104 }1105 /*1106 * Add a new obj on top of the ast stack.1107 * If new length is required, then add also a new length in length stack.1108 */1109 protected void pushOnAstStack(Object node, boolean newLength) {1110 if (node == null) {1111 this.astLengthStack[++this.astLengthPtr] = 0;1112 return;1113 }1114 int stackLength = this.astStack.length;1115 if (++this.astPtr >= stackLength) {1116 System.arraycopy(...

Full Screen

Full Screen

EntityLogicImpl.java

Source:EntityLogicImpl.java Github

copy

Full Screen

...50 super(metaObject, context);51 }52 /**53 * A collection of MOF ids for entities that have dynamic54 * identifiers present.55 */56 private static final Collection dynamicIdentifiersPresent = new ArrayList();57 /**58 * @see org.andromda.core.metafacade.MetafacadeBase#initialize()59 */60 public void initialize()61 {62 super.initialize();63 // if there are no identifiers on this entity, create and add one.64 // enumeration don't have identifiers since they are not entities65 if (!this.isIdentifiersPresent() && this.isAllowDefaultIdentifiers())66 {67 this.createIdentifier();68 dynamicIdentifiersPresent.add(this.getId());69 }70 }71 /**72 * Overridden to provide name masking.73 *74 * @see org.andromda.metafacades.uml.ModelElementFacade#getName()75 */76 @Override77 protected String handleGetName()78 {79 final String nameMask = String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.ENTITY_NAME_MASK));80 return NameMasker.mask(81 super.handleGetName(),82 nameMask);83 }84 /**85 * @see org.andromda.metafacades.uml.Entity#getQueryOperations()86 */87 @Override88 protected Collection<OperationFacade> handleGetQueryOperations()89 {90 return this.getQueryOperations(false);91 }92 /**93 * @see org.andromda.metafacades.uml.Entity#getQueryOperations(boolean)94 */95 @Override96 protected Collection<OperationFacade> handleGetQueryOperations(final boolean follow)97 {98 final Collection<OperationFacade> operations = new ArrayList<OperationFacade>(this.getOperations());99 final Collection<OperationFacade> queryOperations = new ArrayList<OperationFacade>();100 MetafacadeUtils.filterByType(101 operations,102 EntityQueryOperation.class);103 for (OperationFacade operation : operations)104 {105 queryOperations.add((EntityQueryOperation)operation);106 }107 for (ClassifierFacade superClass = (ClassifierFacade)getGeneralization(); superClass != null && follow;108 superClass = (ClassifierFacade)superClass.getGeneralization())109 {110 if (Entity.class.isAssignableFrom(superClass.getClass()))111 {112 Entity entity = (Entity)superClass;113 queryOperations.addAll(entity.getQueryOperations());114 }115 }116 return queryOperations;117 }118 /**119 * @see org.andromda.metafacades.uml.Entity#getIdentifiers()120 */121 @Override122 protected Collection<ModelElementFacade> handleGetIdentifiers()123 {124 return this.getIdentifiers(true);125 }126 /**127 * @see org.andromda.metafacades.uml.Entity#getIdentifiers(boolean)128 */129 @Override130 protected Collection<ModelElementFacade> handleGetIdentifiers(final boolean follow)131 {132 return EntityMetafacadeUtils.getIdentifiers(133 this,134 follow);135 }136 /**137 * Creates an identifier from the default identifier properties specified within a namespace.138 */139 private void createIdentifier()140 {141 // first check if the foreign identifier flag is set, and142 // let those taken precedence if so143 if (!this.checkForAndAddForeignIdentifiers())144 {145 this.createIdentifier(146 this.getDefaultIdentifier(),147 this.getDefaultIdentifierType(),148 this.getDefaultIdentifierVisibility());149 }150 }151 /**152 * Creates a new identifier and adds it to the underlying meta model153 * classifier instance.154 *155 * @param name the name to give the identifier156 * @param type the type to give the identifier157 * @param visibility the visibility to give the identifier158 */159 private void createIdentifier(160 final String name,161 final String type,162 final String visibility)163 {164 final Classifier classifier = (Classifier)this.metaObject;165 // if we auto-create entity identifiers it will only be on hierarchy roots,166 // problems would arise when calls to #checkForAndAddForeignIdentifiers()167 // navigate over associated entities, effectively initializing their facade instances:168 // this results in subclasses having an identifier generated before their ancestors169 // ideally the method mentioned above would not make use of facades but meta-classes only,170 // if one is to refactor it that way this comment may be removed together with the line of code under it171 //172 // notice how the next line of code does not make use of facades, this is done on purpose in order173 // to avoid using uninitialized facades174 //175 // (Wouter, Sept. 20 2006) also see other UML implementations176 if (!classifier.getGeneralization().isEmpty()) return;177 // only create the identifier if an identifer with the name doesn't178 // already exist179 if (!UML14MetafacadeUtils.attributeExists(180 classifier,181 name))182 {183 final Attribute identifier =184 UML14MetafacadeUtils.createAttribute(185 name,186 type,187 visibility,188 MetafacadeConstants.NAMESPACE_SCOPE_OPERATOR);189 identifier.getStereotype().add(190 UML14MetafacadeUtils.findOrCreateStereotype(UMLProfile.STEREOTYPE_IDENTIFIER));191 classifier.getFeature().add(identifier);192 }193 }194 /**195 * @see org.andromda.metafacades.uml.Entity#isIdentifiersPresent()196 */197 @Override198 protected boolean handleIsIdentifiersPresent()199 {200 final Collection<ModelElementFacade> identifiers = this.getIdentifiers(true);201 return identifiers != null && !identifiers.isEmpty();202 }203 /**204 * @see org.andromda.metafacades.uml.Entity#isDynamicIdentifiersPresent()205 */206 @Override207 protected boolean handleIsDynamicIdentifiersPresent()208 {209 return dynamicIdentifiersPresent.contains(this.getId());210 }211 /**212 * @see org.andromda.metafacades.uml.Entity#getTableName()213 */214 @Override215 protected String handleGetTableName()216 {217 final String prefixProperty = UMLMetafacadeProperties.TABLE_NAME_PREFIX;218 final String tableNamePrefix =219 this.isConfiguredProperty(prefixProperty)220 ? ObjectUtils.toString(this.getConfiguredProperty(prefixProperty)) : null;221 return EntityMetafacadeUtils.getSqlNameFromTaggedValue(222 tableNamePrefix,223 this,224 UMLProfile.TAGGEDVALUE_PERSISTENCE_TABLE,225 this.getMaxSqlNameLength(),226 this.getConfiguredProperty(UMLMetafacadeProperties.SQL_NAME_SEPARATOR),227 this.getConfiguredProperty(UMLMetafacadeProperties.SHORTEN_SQL_NAMES_METHOD));228 }229 /**230 * @see org.andromda.metafacades.uml.Entity#getOperationCallFromAttributes(boolean)231 */232 @Override233 protected String handleGetOperationCallFromAttributes(final boolean withIdentifiers)234 {235 return this.getOperationCallFromAttributes(236 withIdentifiers,237 false);238 }239 /**240 * @see org.andromda.metafacades.uml.Entity#getOperationCallFromAttributes(boolean, boolean)241 */242 @Override243 protected String handleGetOperationCallFromAttributes(244 final boolean withIdentifiers,245 final boolean follow)246 {247 final StringBuilder buffer = new StringBuilder();248 String separator = "";249 buffer.append('(');250 final Collection<AttributeFacade> attributes = new ArrayList(this.getAttributes());251 for (ClassifierFacade superClass = (ClassifierFacade)getGeneralization(); superClass != null && follow;252 superClass = (ClassifierFacade)superClass.getGeneralization())253 {254 if (superClass instanceof Entity)255 {256 final Entity entity = (Entity)superClass;257 attributes.addAll(entity.getAttributes());258 }259 }260 if (!attributes.isEmpty())261 {262 for (final Iterator iterator = attributes.iterator(); iterator.hasNext();)263 {264 final EntityAttribute attribute = (EntityAttribute)iterator.next();265 if (withIdentifiers || !attribute.isIdentifier())266 {267 buffer.append(separator);268 if (attribute.getType() != null)269 {270 buffer.append(attribute.getType().getFullyQualifiedName());271 }272 buffer.append(' ');273 buffer.append(attribute.getName());274 separator = ", ";275 }276 }277 }278 buffer.append(')');279 return buffer.toString();280 }281 /**282 * @see org.andromda.metafacades.uml.Entity#getAttributeTypeList(boolean, boolean)283 */284 @Override285 protected String handleGetAttributeTypeList(286 final boolean follow,287 final boolean withIdentifiers)288 {289 return this.getTypeList(this.getAttributes(290 follow,291 withIdentifiers));292 }293 /**294 * @see org.andromda.metafacades.uml.Entity#getAttributeNameList(boolean, boolean)295 */296 @Override297 protected String handleGetAttributeNameList(298 final boolean follow,299 final boolean withIdentifiers)300 {301 return this.getNameList(this.getAttributes(302 follow,303 withIdentifiers));304 }305 /**306 * @see org.andromda.metafacades.uml.Entity#getAttributeNameList(boolean, boolean, boolean)307 */308 @Override309 protected String handleGetAttributeNameList(310 final boolean follow,311 final boolean withIdentifiers,312 final boolean withDerived)313 {314 return this.getNameList(this.getAttributes(315 follow,316 withIdentifiers,317 withDerived));318 }319 /**320 * @see org.andromda.metafacades.uml.Entity#getRequiredAttributeTypeList(boolean, boolean)321 */322 @Override323 protected String handleGetRequiredAttributeTypeList(324 final boolean follow,325 final boolean withIdentifiers)326 {327 return this.getTypeList(this.getRequiredAttributes(328 follow,329 withIdentifiers));330 }331 /**332 * @see org.andromda.metafacades.uml.Entity#getRequiredAttributeNameList(boolean, boolean)333 */334 @Override335 protected String handleGetRequiredAttributeNameList(336 final boolean follow,337 final boolean withIdentifiers)338 {339 return this.getNameList(this.getRequiredAttributes(340 follow,341 withIdentifiers));342 }343 /**344 * @see org.andromda.metafacades.uml.Entity#getRequiredPropertyTypeList(boolean, boolean)345 */346 @Override347 protected String handleGetRequiredPropertyTypeList(348 final boolean follow,349 final boolean withIdentifiers)350 {351 return this.getTypeList(this.getRequiredProperties(352 follow,353 withIdentifiers));354 }355 /**356 * @see org.andromda.metafacades.uml.Entity#getRequiredPropertyNameList(boolean, boolean)357 */358 @Override359 protected String handleGetRequiredPropertyNameList(360 final boolean follow,361 final boolean withIdentifiers)362 {363 return this.getNameList(this.getRequiredProperties(364 follow,365 withIdentifiers));366 }367 /**368 * Constructs a comma separated list of attribute type names from the passed in collection of369 * <code>attributes</code>.370 *371 * @param attributes the attributes to construct the list from.372 * @return the comma separated list of attribute types.373 */374 private String getTypeList(final Collection attributes)375 {376 final StringBuilder list = new StringBuilder();377 final String comma = ", ";378 CollectionUtils.forAllDo(379 attributes,380 new Closure()381 {382 public void execute(final Object object)383 {384 if (object instanceof AttributeFacade)385 {386 final AttributeFacade attribute = (AttributeFacade)object;387 if (attribute.getType() != null)388 {389 list.append(attribute.getType().getFullyQualifiedName());390 list.append(comma);391 }392 }393 if (object instanceof AssociationEndFacade)394 {395 final AssociationEndFacade associationEnd = (AssociationEndFacade)object;396 if (associationEnd.getType() != null)397 {398 list.append(associationEnd.getType().getFullyQualifiedName());399 list.append(comma);400 }401 }402 }403 });404 if (list.toString().endsWith(comma))405 {406 list.delete(407 list.lastIndexOf(comma),408 list.length());409 }410 return list.toString();411 }412 /**413 * Constructs a comma separated list of attribute names from the passed in collection of <code>attributes</code>.414 *415 * @param properties the properties to construct the list from.416 * @return the comma separated list of attribute names.417 */418 private String getNameList(final Collection properties)419 {420 final StringBuilder list = new StringBuilder();421 final String comma = ", ";422 CollectionUtils.forAllDo(423 properties,424 new Closure()425 {426 public void execute(Object object)427 {428 if (object instanceof EntityAttribute)429 {430 list.append(((AttributeFacade)object).getName());431 list.append(comma);432 }433 if (object instanceof EntityAssociationEnd)434 {435 list.append(((AssociationEndFacade)object).getName());436 list.append(comma);437 }438 }439 });440 if (list.toString().endsWith(comma))441 {442 list.delete(443 list.lastIndexOf(comma),444 list.length());445 }446 return list.toString();447 }448 /**449 * @see org.andromda.metafacades.uml.Entity#isChild()450 */451 @Override452 protected boolean handleIsChild()453 {454 return CollectionUtils.find(455 this.getAssociationEnds(),456 new Predicate()457 {458 public boolean evaluate(Object object)459 {460 return ((AssociationEndFacade)object).getOtherEnd().isComposition();461 }462 }) != null;463 }464 /**465 * @see org.andromda.metafacades.uml.Entity#getParentEnd()466 */467 @Override468 protected AssociationEndFacade handleGetParentEnd()469 {470 AssociationEndFacade parentEnd = null;471 final AssociationEndFacade end =472 (AssociationEndFacade)CollectionUtils.find(473 this.getAssociationEnds(),474 new Predicate()475 {476 public boolean evaluate(Object object)477 {478 return ((AssociationEndFacade)object).getOtherEnd().isComposition();479 }480 });481 if (end != null)482 {483 parentEnd = end.getOtherEnd();484 }485 return parentEnd;486 }487 /**488 * @see org.andromda.metafacades.uml.Entity#getChildEnds()489 */490 @Override491 protected Collection<AssociationEndFacade> handleGetChildEnds()492 {493 final Collection<AssociationEndFacade> childEnds =494 new FilteredCollection(this.getAssociationEnds())495 {496 private static final long serialVersionUID = -4602337379703645043L;497 public boolean evaluate(Object object)498 {499 return ((AssociationEndFacade)object).isComposition();500 }501 };502 CollectionUtils.transform(503 childEnds,504 new Transformer()505 {506 public Object transform(Object object)507 {508 return ((AssociationEndFacade)object).getOtherEnd();509 }510 });511 return childEnds;512 }513 /**514 * @see org.andromda.metafacades.uml.Entity#getBusinessOperations()515 */516 @Override517 protected Collection<OperationFacade> handleGetBusinessOperations()518 {519 final Collection<OperationFacade> businessOperations = new ArrayList(this.getImplementationOperations());520 MetafacadeUtils.filterByNotType(521 businessOperations,522 EntityQueryOperation.class);523 return businessOperations;524 }525 /**526 * @see org.andromda.metafacades.uml.Entity#getEntityReferences()527 */528 @Override529 protected Collection<DependencyFacade> handleGetEntityReferences()530 {531 return new FilteredCollection(this.getSourceDependencies())532 {533 private static final long serialVersionUID = -8696886289865317133L;534 public boolean evaluate(Object object)535 {536 ModelElementFacade targetElement = ((DependencyFacade)object).getTargetElement();537 return targetElement instanceof Entity;538 }539 };540 }541 /**542 * @see org.andromda.metafacades.uml.Entity#getAttributes(boolean, boolean)543 */544 @Override545 protected Collection handleGetAttributes(546 boolean follow,547 final boolean withIdentifiers)548 {549 return this.getAttributes(follow, withIdentifiers, true);550 }551 /**552 * @see org.andromda.metafacades.uml.Entity#getAttributes(boolean, boolean, boolean)553 */554 @Override555 protected Collection handleGetAttributes(556 boolean follow,557 final boolean withIdentifiers,558 final boolean withDerived)559 {560 final Collection attributes = this.getAttributes(follow);561 CollectionUtils.filter(562 attributes,563 new Predicate()564 {565 public boolean evaluate(Object object)566 {567 boolean valid = true;568 if (!withIdentifiers && object instanceof EntityAttribute)569 {570 valid = !((EntityAttribute)object).isIdentifier();571 }572 if (valid && !withDerived && object instanceof EntityAttribute)573 {574 valid = !((EntityAttribute)object).isDerived();575 }576 return valid;577 }578 });579 return attributes;580 }581 /**582 * @see org.andromda.metafacades.uml.Entity#getProperties(boolean, boolean)583 */584 @Override585 protected Collection handleGetProperties(586 boolean follow,587 final boolean withIdentifiers)588 {589 final Collection properties = this.getProperties(follow);590 CollectionUtils.filter(591 properties,592 new Predicate()593 {594 public boolean evaluate(Object object)595 {596 boolean valid = true;597 if (!withIdentifiers && object instanceof EntityAttribute)598 {599 valid = !((EntityAttribute)object).isIdentifier();600 }601 return valid;602 }603 });604 return properties;605 }606 /**607 * @see org.andromda.metafacades.uml.Entity#getRequiredAttributes(boolean, boolean)608 */609 @Override610 protected Collection handleGetRequiredAttributes(611 boolean follow,612 final boolean withIdentifiers)613 {614 final Collection attributes = this.getAttributes(615 follow,616 withIdentifiers, false);617 CollectionUtils.filter(618 attributes,619 new Predicate()620 {621 public boolean evaluate(Object object)622 {623 boolean valid;624 valid = ((AttributeFacade)object).isRequired();625 if (valid && !withIdentifiers && object instanceof EntityAttribute)626 {627 valid = !((EntityAttribute)object).isIdentifier();628 }629 return valid;630 }631 });632 return attributes;633 }634 /**635 * @see org.andromda.metafacades.uml.Entity#getRequiredProperties(boolean, boolean)636 */637 @Override638 protected Collection handleGetRequiredProperties(639 final boolean follow,640 final boolean withIdentifiers)641 {642 final Set properties = new LinkedHashSet(this.getProperties(643 follow,644 withIdentifiers));645 CollectionUtils.filter(646 properties,647 new Predicate()648 {649 public boolean evaluate(final Object object)650 {651 boolean valid = false;652 if (object instanceof AttributeFacade)653 {654 AttributeFacade attribute = (AttributeFacade)object;655 valid = attribute.isRequired() && !attribute.isDerived();656 if (valid && !withIdentifiers && object instanceof EntityAttribute)657 {658 valid = !((EntityAttribute)object).isIdentifier();659 }660 }661 else if (object instanceof AssociationEndFacade)662 {663 valid = ((AssociationEndFacade)object).isRequired();664 }665 return valid;666 }667 });668 List sortedProperties = new ArrayList(properties);669 MetafacadeUtils.sortByFullyQualifiedName(sortedProperties);670 return sortedProperties;671 }672 /**673 * Gets the maximum name length SQL names may be674 */675 @Override676 protected short handleGetMaxSqlNameLength()677 {678 return Short.valueOf((String)this.getConfiguredProperty(UMLMetafacadeProperties.MAX_SQL_NAME_LENGTH));679 }680 /**681 * Returns true/false on whether or not default identifiers are allowed682 */683 private boolean isAllowDefaultIdentifiers()684 {685 return Boolean.valueOf((String)this.getConfiguredProperty(UMLMetafacadeProperties.ALLOW_DEFAULT_IDENTITIFIERS))686 .booleanValue();687 }688 /**689 * Gets the name of the default identifier.690 */691 private String getDefaultIdentifier()692 {693 return ObjectUtils.toString(this.getConfiguredProperty(UMLMetafacadeProperties.DEFAULT_IDENTIFIER_PATTERN))694 .replaceAll(695 "\\{0\\}",696 StringUtilsHelper.lowerCamelCaseName(this.getName()));697 }698 /**699 * Gets the name of the default identifier type.700 */701 private String getDefaultIdentifierType()702 {703 return (String)this.getConfiguredProperty(UMLMetafacadeProperties.DEFAULT_IDENTIFIER_TYPE);704 }705 /**706 * Gets the default identifier visibility.707 */708 private String getDefaultIdentifierVisibility()709 {710 return (String)this.getConfiguredProperty(UMLMetafacadeProperties.DEFAULT_IDENTIFIER_VISIBILITY);711 }712 /**713 * Checks to see if this entity has any associations where the foreign identifier flag may be set, and if so creates714 * and adds identifiers just like the foreign entity to this entity.715 *716 * @return true if any identifiers were added, false otherwise717 */718 private boolean checkForAndAddForeignIdentifiers()719 {720 boolean identifiersAdded = false;721 final EntityAssociationEnd end = this.getForeignIdentifierEnd();722 if (end != null && end.getType() instanceof Entity)723 {724 final Entity foreignEntity = (Entity)end.getOtherEnd().getType();725 final Collection<ModelElementFacade> identifiers = EntityMetafacadeUtils.getIdentifiers(726 foreignEntity,727 true);728 for (final ModelElementFacade facade : identifiers)729 {730 if (facade instanceof AttributeFacade)731 {732 AttributeFacade identifier = (AttributeFacade)facade;733 this.createIdentifier(734 identifier.getName(),735 identifier.getType().getFullyQualifiedName(true),736 identifier.getVisibility());737 }738 else if (facade instanceof AssociationEndFacade)739 {740 AssociationEndFacade identifier = (AssociationEndFacade)facade;741 this.createIdentifier(742 identifier.getName(),743 identifier.getType().getFullyQualifiedName(true),744 identifier.getVisibility());745 }746 identifiersAdded = true;747 }748 }749 return identifiersAdded;750 }751 /**752 * Override to filter out any association ends that point to model elements other than other entities.753 *754 * @see org.andromda.metafacades.uml.ClassifierFacade#getAssociationEnds()755 */756 @Override757 public List handleGetAssociationEnds()758 {759 final List associationEnds = (List)this.shieldedElements(super.handleGetAssociationEnds());760 CollectionUtils.filter(761 associationEnds,762 new Predicate()763 {764 public boolean evaluate(Object object)765 {766 return ((AssociationEndFacade)object).getOtherEnd().getType() instanceof Entity;767 }768 });769 return associationEnds;770 }771 /**772 * @see org.andromda.metafacades.uml14.EntityLogic#handleIsUsingForeignIdentifier()773 */774 protected boolean handleIsUsingForeignIdentifier()775 {776 return this.getForeignIdentifierEnd() != null;777 }778 /**779 * Gets the association end that is flagged as having the foreign identifier set (or null if none is).780 */781 private EntityAssociationEnd getForeignIdentifierEnd()782 {783 return (EntityAssociationEnd)CollectionUtils.find(784 this.getAssociationEnds(),785 new Predicate()786 {787 public boolean evaluate(Object object)788 {789 boolean valid = false;790 if (object != null && EntityAssociationEnd.class.isAssignableFrom(object.getClass()))791 {792 EntityAssociationEnd end = (EntityAssociationEnd)object;793 valid = end.isForeignIdentifier();794 }795 return valid;796 }797 });798 }799 /**800 * @see org.andromda.metafacades.uml.Entity#isUsingAssignedIdentifier()801 */802 @Override803 protected boolean handleIsUsingAssignedIdentifier()804 {805 boolean assigned = false;806 final Collection<ModelElementFacade> identifiers = this.getIdentifiers();807 if (identifiers != null && !identifiers.isEmpty())808 {809 ModelElementFacade facade = identifiers.iterator().next();810 if (facade instanceof AttributeFacade)811 {812 final AttributeFacade identifier = (AttributeFacade)facade;813 assigned =814 Boolean.valueOf(815 ObjectUtils.toString(816 identifier.findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_ASSIGNED_IDENTIFIER)))817 .booleanValue();818 }819 }820 return assigned;821 }822 /**823 * @see org.andromda.metafacades.uml.Entity#getSchema()824 */825 @Override826 protected String handleGetSchema()827 {828 String schemaName = ObjectUtils.toString(this.findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_SCHEMA));829 if (StringUtils.isBlank(schemaName))830 {831 schemaName = ObjectUtils.toString(this.getConfiguredProperty(UMLMetafacadeProperties.SCHEMA_NAME));832 }833 return schemaName;834 }835 /**836 * @see org.andromda.metafacades.uml.Entity#getIdentifierAssociationEnds()837 */838 @Override839 protected Collection handleGetIdentifierAssociationEnds()840 {841 final Collection<AssociationEndFacade> associationEnds = new ArrayList<AssociationEndFacade>(this.getAssociationEnds());842 MetafacadeUtils.filterByStereotype(843 associationEnds,844 UMLProfile.STEREOTYPE_IDENTIFIER);845 return associationEnds;846 }847 /**848 * @see org.andromda.metafacades.uml.Entity#isCompositeIdentifier()849 */850 @Override851 protected boolean handleIsCompositeIdentifier()852 {853 int identifiers = (!this.getIdentifiers().isEmpty()) ? this.getIdentifiers().size() : 0;854 identifiers =855 identifiers +856 (!this.getIdentifierAssociationEnds().isEmpty() ? this.getIdentifierAssociationEnds().size() : 0);857 return identifiers >= 2;858 }859 /**860 * @see org.andromda.metafacades.uml.Entity#getAllEntityReferences()861 */862 @Override863 protected Collection<DependencyFacade> handleGetAllEntityReferences()864 {865 final Collection<DependencyFacade> result = new LinkedHashSet<DependencyFacade> ();866 // get references of the service itself867 result.addAll(this.getEntityReferences());868 // get references of all super classes869 CollectionUtils.forAllDo(this.getAllGeneralizations(), new Closure()870 {871 public void execute(Object object)...

Full Screen

Full Screen

HangingPunctuationValidator.java

Source:HangingPunctuationValidator.java Github

copy

Full Screen

1/*2 * SonarQube CSS / SCSS / Less Analyzer3 * Copyright (C) 2013-2017 David RACODON4 * mailto: david.racodon@gmail.com5 *6 * This program is free software; you can redistribute it and/or7 * modify it under the terms of the GNU Lesser General Public8 * License as published by the Free Software Foundation; either9 * version 3 of the License, or (at your option) any later version.10 *11 * This program is distributed in the hope that it will be useful,12 * but WITHOUT ANY WARRANTY; without even the implied warranty of13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14 * Lesser General Public License for more details.15 *16 * You should have received a copy of the GNU Lesser General Public License17 * along with this program; if not, write to the Free Software Foundation,18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.19 */20package org.sonar.css.model.property.validator.property;21import java.util.List;22import org.sonar.css.model.property.validator.ValueValidator;23import org.sonar.css.model.property.validator.valueelement.IdentifierValidator;24import org.sonar.plugins.css.api.tree.Tree;25import org.sonar.plugins.css.api.tree.css.ValueTree;26public class HangingPunctuationValidator implements ValueValidator {27 private static final IdentifierValidator SINGLE_ELEMENT_VALIDATOR = new IdentifierValidator("none", "first", "force-end", "allow-end", "last");28 private static final IdentifierValidator FIRST_VALIDATOR = new IdentifierValidator("first");29 private static final IdentifierValidator LAST_VALIDATOR = new IdentifierValidator("last");30 private static final IdentifierValidator FORCE_END_ALLOW_END_VALIDATOR = new IdentifierValidator("force-end", "allow-end");31 @Override32 public boolean isValid(ValueTree valueTree) {33 List<Tree> valueElements = valueTree.sanitizedValueElements();34 int numberOfValueElements = valueElements.size();35 if (numberOfValueElements > 3) {36 return false;37 }38 if (numberOfValueElements == 1) {39 return SINGLE_ELEMENT_VALIDATOR.isValid(valueElements.get(0));40 }41 if (numberOfValueElements > 1) {42 return validateMultiElementValue(valueElements);43 }44 return false;45 }46 @Override47 public String getValidatorFormat() {48 return "none | [ first || [ force-end | allow-end ] || last ]";49 }50 private boolean validateMultiElementValue(List<Tree> valueElements) {51 int first = 0;52 int forceEndAllowEnd = 0;53 int last = 0;54 for (Tree valueElement : valueElements) {55 if (FIRST_VALIDATOR.isValid(valueElement)) {56 first++;57 } else if (LAST_VALIDATOR.isValid(valueElement)) {58 last++;59 } else if (FORCE_END_ALLOW_END_VALIDATOR.isValid(valueElement)) {60 forceEndAllowEnd++;61 }62 }63 if (first > 1 || last > 1 || forceEndAllowEnd > 1) {64 return false;65 } else {66 return first + forceEndAllowEnd + last == valueElements.size();67 }68 }69}...

Full Screen

Full Screen

identifier

Using AI Code Generation

copy

Full Screen

1 @d = {:five => 5, :six => "six"}2 @d = {:five => 5, :six => "six"}3 @d = {:five => 5, :six => "six"}4 @d = {:five => 5, :six => "six"}

Full Screen

Full Screen

identifier

Using AI Code Generation

copy

Full Screen

1 @d = {:five => 5, :six => "six"}2 @d = {:five => 5, :six => "six"}3 @d = {:five => 5, :six => "six"}4 @d = {:five => 5, :six => "six"}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Unobtainium_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful